import pytest
import allure

from pages.task_info.create_quick_visit_page import Create_quick_visit_page
from pages.work_info.team_page import TeamPage
from pages.persional_info.login_page import LoginPage
from pages.persional_info.persion_center_page import Persion_center_Page
from pages.task_info.quick_visit_page import Quick_visit_page
from pages.task_info.visit_customer_page import Visit_customer_page
from pages.work_info.work_bench_page import Work_bench_Page
from utils.assert_util.assert_executor import AssertionExecutor
from utils.driver_manager import DriverManager
from data.data_loader import DataLoader


class BaseTest:

    """测试基类，提供通用功能"""
    @staticmethod
    def get_test_data(filename: str = None, test_case_name: str = None) -> list:
        """获取测试数据 - 简化调用"""
        return DataLoader().get_test_data('json',filename,test_case_name)

    @pytest.fixture(autouse=True)
    def setup_class(self):
        """每个测试用例执行前的准备工作"""
        self.driver = DriverManager.get_driver()
        self.login_page = LoginPage(self.driver)
        self.team_page = TeamPage(self.driver)
        self.work_bench_page =Work_bench_Page(self.driver)
        self.quit_page = Quick_visit_page(self.driver)
        self.visit_customer_page = Visit_customer_page(self.driver)
        self.persion_center_page = Persion_center_Page(self.driver)
        self.create_quick_page = Create_quick_visit_page(self.driver)
        # 初始化断言执行器
        self.assertion_executor = AssertionExecutor(self.driver)

    def teardown_class(cls):
        DriverManager.get_driver().terminate_app('com.topboya.linker')


    def take_screenshot(self, name: str):
        """截图并添加到allure报告"""
        screenshot_path = f"screenshots/{name}.png"
        self.driver.save_screenshot(screenshot_path)
        allure.attach.file(screenshot_path, name=f"{name}截图",
                           attachment_type=allure.attachment_type.PNG)

    def log_step(self, message: str):
        """记录测试步骤"""
        allure.step(message)